package com.liang.lesson03;
import com.liang.lesson2.JdbcUntils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TestSelect {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;
        try {
             conn = JdbcUntils.getConnection();
             String sql = "select * from users where id = ?";//编写sql
             st = conn.prepareStatement(sql);//预编译
             st.setInt(1,2);//传递参数
             rs= st.executeQuery();//执行
            if(rs.next()){
                System.out.println(rs.getString("NAME"));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            JdbcUntils.release(conn,st,rs);
        }
    }
}
